<template>
    <div>
      <el-row>
          <el-col :span="10" :offset="7">
              请输入打包单编号：<el-input v-model="salePackManageVo.pno"></el-input>
              <el-button type="success" @click="getSaleMsg">查看商品信息</el-button>
          </el-col>
      </el-row>
      <el-row>
          <el-col>
              <template>
                  <el-select v-model="outStockDTO.type" placeholder="请选择出库单类型">
                      <el-option label="销售出库" value="1"></el-option>
                      <el-option label="代存出库" value="2"></el-option>
                  </el-select>               
                  <el-button type="primary" @click="addForm">立即添加</el-button>
                  <el-button @click="this.goDetailin">取消</el-button>
              </template>
          </el-col>
      </el-row>
      <el-row>
          <el-col>
              <template>
                  <el-table
                      :data="goodsList"
                      tooltip-effect="dark"
                      style="width: 100%">
                      <el-table-column type="index" :index="indexMethod">
                      </el-table-column>
                      <el-table-column prop="goodsName" label="商品名"> </el-table-column>
                      <el-table-column prop="count" label="数量"> </el-table-column>
                      <el-table-column prop="weight" label="重量"> </el-table-column>
                      <el-table-column prop="unitPrice" label="价格/克"> </el-table-column>
                  </el-table>
              </template>
          </el-col>
      </el-row>
    </div>
  </template>
  
  <script>
  export default {
      data() {
        return {
          outStockDTO:{
              saleId: null,
              formMaker:"",
              type: null,
              customer: null,
              depotId: null,
              items: [],
          },
          goodsList: [],
          depotList: [],
          salePackManageVo: {
            pno: '',
            current: 1,
            size: 10,
          },
        };
      },
      mounted: function(){
          this.outStockDTO.formMaker = window.localStorage.getItem("account");
          this.$axios.get("/depot/listForInStock").then(result => {
              this.depotList = result.data.data;
          });
      },
      methods: {
          getSaleMsg(){
              this.$axios.post("salePack/managePack",this.salePackManageVo).then(res => {
                  var goodsList2 = res.data.data.data[0].orderItemList
                  this.goodsList = res.data.data.data[0].orderItemList
                  this.outStockDTO.customer = res.data.data.data[0].customer
                  this.outStockDTO.saleId = res.data.data.data[0].pno
                  this.outStockDTO.depotId = res.data.data.data[0].depotId
   
                  var arr=[]
                  for (let i = 0; i< goodsList2.length; i++) {
                      arr.push({itemCode:goodsList2[i].goodsNumber,num:goodsList2[i].count})
                             
                      }
                      this.outStockDTO.items = arr;    
              });
          },
          indexMethod(index) {
              return index + 1;
          },
          addForm(){
              console.log(this.outStockDTO);
              this.$axios.post("/outStock/insert",this.outStockDTO).then(res => {
                  this.goDetailin();
              })
          },
          goDetailin(){
              this.$router.push("/detailout");
          },
      }
  }
  </script>
  
  <style scoped>
  </style>